using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Needle.Utils.Collections
{
    public class RichList<T> : List<T>, IRichList<T>
    {

        public RichList()
        { }

        public RichList(int capacity)
            : base(capacity)
        { }

        public RichList(IEnumerable<T> collection)
            : base(collection)
        { }

        public new IRichList<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)
        {
            if (converter == null)
                throw new ArgumentNullException("converter", "converter is null.");
            var newList = new RichList<TOutput>(Capacity);
            ForEach(item => newList.Add(converter(item)));
            return newList;
        }

        public new IRichList<T> FindAll(Predicate<T> match)
        {
            if (match == null)
                throw new ArgumentNullException("match", "match is null.");
            var newList = new RichList<T>();
            ForEach(item => { if (match(item)) newList.Add(item); });
            return newList;
        }

        public new IRichList<T> GetRange(int index, int count)
        {
            int lastIndexPlusOne = index + count;
            if (lastIndexPlusOne > this.Count)
                throw new ArgumentOutOfRangeException();
            var newList = new RichList<T>(count);
            for (int i = index; i < lastIndexPlusOne; i++)
                newList.Add(this[i]);
            return newList;
        }

        public new IRichList<T> AsReadOnly()
        {
            return new ReadOnlyRichCollection<T>(this);
        }
    }
}
